home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / ssavwin.exe / SSAVEDEM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-05-12  |  10.0 KB  |  207 lines

  1. (****************************************************************************
  2. *****************************************************************************
  3. *                                                                           *
  4. *  SsaveDem.pas: Demo for the Borland Pascal Screen Saver units.            *
  5. *                                                                           *
  6. *****************************************************************************
  7. *                                                                           *
  8. *  Compiler: BP 7.0                                                         *
  9. *                                                                           *
  10. *  The resulting .EXE file must be renamed to .SCR and copied to the        *
  11. *  windows directory for Control Panel to find it. Be sure not to           *
  12. *  forget the line {$D SCRNSAVE <name>} to give the saver a name.           *
  13. *                                                                           *
  14. *****************************************************************************
  15. *                                                                           *
  16. *  Copyright ⌐ 1993 Manfred Keul [100031,12].                               *
  17. *                                                                           *
  18. *  Rev. 0.1   19.4.93   MK  IR                                              *
  19. *                                                                           *
  20. ****************************************************************************)
  21.  
  22. uses OWindows, ODialogs, Wintypes, Winprocs, SSaveWin, SSavePwd, Traps;
  23.  
  24. {$I savedrc.inc           contains rc constants }
  25. {$R ssavedem.res          contains configuration dialog layout }
  26.  
  27. { $define Lazy     }          { Define one of these constants...}
  28. { $define Text     }
  29. { $define Ellipses }
  30. { $define Spotlight}
  31. {$define Tubes    }          {.. to select an animation module }
  32.  
  33. {****************************************************************************
  34. *                                                                           *
  35. *                        T M y S a v e r W i n                              *
  36. *                                                                           *
  37. *  Sample screen saver window, descendant of TScSaverWin (unit SSaveWin).   *
  38. *                                                                           *
  39. ****************************************************************************}
  40.  
  41. { Plug in one of the sample savers by $DEFINing one of the above constants.
  42.   Most of the samples do nothing more than to override the DoTheShow method
  43.   of TScSaverWin with their own animation. }
  44.  
  45. {$ifdef Lazy     } {$I LazySavr.pas           just blank }  {$endif }
  46. {$ifdef Text     } {$I TextSavr.pas           some text }   {$endif }
  47. {$ifdef Ellipses } {$I EllpSavr.pas           ellipses }    {$endif }
  48. {$ifdef Spotlight} {$I SpotSavr.pas           spotlight }   {$endif }
  49. {$ifdef Tubes    } {$I TubeSavr.pas           tubes }       {$endif }
  50.  
  51. {****************************************************************************
  52. *                                                                           *
  53. *                        T S c r S a v A p p                                *
  54. *                                                                           *
  55. *  Application object. Generates a window of type TMySaverWin (descendant   *
  56. *  of TScSaverWin, unit SSaveWin). Must call the DoTheShow method of this   *
  57. *  window within its IdleAction method.                                     *
  58. *                                                                           *
  59. ****************************************************************************}
  60.  
  61. type
  62.   TScrSavApp = object (TApplication)
  63.     procedure InitMainWindow; virtual;
  64.     function IdleAction: boolean; virtual;
  65.   end;
  66.  
  67. procedure TScrSavApp.InitMainWindow;
  68. begin
  69. MainWindow := New (PMySaverWin, Init (nil, AppName))
  70. end;
  71.  
  72. function TScrSavApp.IdleAction: boolean;
  73. begin
  74. PMySaverWin (MainWindow)^.DoTheShow;   { call animation routine }
  75. IdleAction := true;                    { call it again and again and again..}
  76. end;
  77.  
  78. {****************************************************************************
  79. *                                                                           *
  80. *                        T S c r C n f D l g                                *
  81. *                                                                           *
  82. *  Dialog window for screen saver configuration, here: only password.       *
  83. *  Descendant objects can contain controls for their individual setup.      *
  84. *                                                                           *
  85. ****************************************************************************}
  86.  
  87. const ConfigClass = 'ScrSavCnfDialog';         { Class name }
  88.  
  89. type
  90.   PScrCnfDlg = ^TScrCnfDlg;
  91.   TScrCnfDlg = object(TDlgWindow)
  92.     DesktopApplet: HWnd;
  93.     constructor Init (aParent:PWindowsObject; aTitle:PChar);
  94.     destructor  Done; virtual;
  95.     function    GetClassName: PChar; virtual;
  96.     procedure   PWBut (var Msg: TMessage); virtual id_First + IDC_PWBut;
  97.   end;
  98.  
  99. {****************************************************************************
  100. *                                                                           *
  101. *           T S c r C n f D l g . I n i t                                   *
  102. *                             - . D o n e                                   *
  103. *                             - . G e t C l a s s N a m e                   *
  104. *                                                                           *
  105. *  NOTE: The Configuration Dialog should be modal. Because there is no easy *
  106. *        way to run an OWL TDialog via the DialogBox function, we must      *
  107. *        disable/enable the Desktop applet by hand in our Init/Done methods.*
  108. *                                                                           *
  109. ****************************************************************************}
  110.  
  111. constructor TScrCnfDlg.Init (aParent: PWindowsObject; aTitle: PChar);
  112. begin
  113. inherited Init (aParent, aTitle);
  114. DesktopApplet := GetActiveWindow;
  115. EnableWindow (DesktopApplet, false);
  116. end;
  117.  
  118. destructor TScrCnfDlg.Done;
  119. begin
  120. EnableWindow (DesktopApplet, true);
  121. BringWindowToTop (DesktopApplet);
  122. inherited Done;
  123. end;
  124.  
  125. function  TScrCnfDlg.GetClassName: PChar;
  126. begin
  127. GetClassName := ConfigClass;
  128. end;
  129.  
  130. {****************************************************************************
  131. *                                                                           *
  132. *                     T S c r C n f D l g . P W B u t                       *
  133. *                                                                           *
  134. *  Responds to the Password button by invoking the password dialog          *
  135. *  (imported from unit SSavePwd.)                                           *
  136. *                                                                           *
  137. ****************************************************************************}
  138.  
  139. procedure TScrCnfDlg.PWBut (var Msg: TMessage);
  140. begin
  141. Application^.ExecDialog (New (PPassWordDialog, Init(@Self, 'NewPWDlg')));
  142. end;
  143.  
  144.  
  145. {****************************************************************************
  146. *                                                                           *
  147. *                        T S c r C n f A p p                                *
  148. *                                                                           *
  149. *  Application object for screen saver configuration. Generates a window of *
  150. *  type TScrCnfDlg.                                                         *
  151. *                                                                           *
  152. ****************************************************************************}
  153.  
  154. type
  155.   TScrCnfApp = object(TApplication)
  156.     procedure InitMainWindow; virtual;
  157.   end;
  158.  
  159. procedure TScrCnfApp.InitMainWindow;
  160. begin
  161. MainWindow := New (PScrCnfDlg, Init (nil,'ConfigDlg'));
  162. end;
  163.  
  164. {****************************************************************************
  165. *****************************************************************************
  166. *                                                                           *
  167. *                        M a i n   P r o g r a m                            *
  168. *                                                                           *
  169. *****************************************************************************
  170. ****************************************************************************}
  171.  
  172. {****************************************************************************
  173. *                                                                           *
  174. *  A screen saver really is "two programs in one". If started with a "/s"   *
  175. *  or "-s" command line parameter, the saver itself should start (in this   *
  176. *  implementation: type TScrSavApp). A "/c" or "-c" invokes the configura-  *
  177. *  tion (TScrCnfApp).                                                       *
  178. *                                                                           *
  179. ****************************************************************************}
  180.  
  181. var ScrSavApp: TScrSavApp;
  182.     ScrCnfApp: TScrCnfApp;
  183.  
  184. begin
  185. if (hPrevInst <> 0) then halt;           { don't start twice }
  186.  
  187. SaverName := AppName;  { override default CONTROL.INI heading in unit SSavePwd }
  188.  
  189. if (Pos ('s', ParamStr(1)) <> 0) or (Pos ('S', ParamStr(1)) <> 0) then
  190.     begin                                { "s" in command line: run saver }
  191.     ScrSavApp.Init (AppName);
  192.     ScrSavApp.Run;
  193.     ScrSavApp.Done;
  194.     end
  195.   else
  196.     begin                               { no "s": must be "c"onfiguration }
  197.     { In fact, we don't need an application object here, because all we want
  198.       to do is to run a dialog box: Windows' DialogBox function would be a
  199.       much cheaper solution. OK, we're in OWL here. And since TDialog needs
  200.       an Application, let's give it one: }
  201.     ScrCnfApp.Init (AppName);
  202.     ScrCnfApp.Run;
  203.     ScrCnfApp.Done;
  204.     end;
  205. end.
  206.  
  207.